﻿<!--
Copyright (c) 2012 
Ulf Björklund
http://average-uffe.blogspot.com/
http://twitter.com/codeplanner
http://twitter.com/ulfbjo

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//-->
@{
    ViewBag.Title = "SinglePage";
}
@if (false)
{ 
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script src="/Scripts/knockout-2.0.0.js" type="text/javascript"></script>           
}
@section JavaScript{
    <script type="text/javascript">

        //Entity, Scaffolded!!!
        var IndustryEntity = function () {
            this.Id = 0;
            this.Created = null;
						this.Updated = ko.observable();
						this.Description = ko.observable();
						this.Key = ko.observable();
												this.Categories = ko.observableArray([]);			
						this.Technologies = ko.observableArray([]);			
						this.ExpertProfiles = ko.observableArray([]);			
						this.CompanyProfiles = ko.observableArray([]);			
						this.Positions = ko.observableArray([]);			
			        };

        $(function () {
            //Setup viewmodel and trigger knockoutjs
            ViewModel.Debug = debugEnabled;
            ViewModel.Setup("Industry", IndustryEntity, function () {
                var cmd = getQuerystring("cmd", null);
                var id = getQuerystring("id", null);
                var sender = getQuerystring("sender", null);
                if (cmd == 'add') {
                    ViewLogic.ShowAddDialog(id,sender);
                }
                if (cmd == 'details') {
                    if (id != null) {
                        ViewModel.Activate(id);
                        ViewLogic.ShowDetails();
                    }
                }
                if (cmd == 'delete') {
                    if (id != null) {
                        ViewModel.Activate(id);
                        ViewLogic.ShowDeleteDialog();
                    }
                }
                if (cmd == 'edit') {
                    if (id != null) {
                        ViewModel.Activate(id);
                        ViewLogic.ShowEditDialog();
                    }
                }
				if (cmd == "index" || cmd == "") {
                    ViewLogic.ShowIndex();
                }
            });            
        });

       var ViewLogic = {
            ShowAddDialog: function (id, sender) {
                $("#details").hide();
                LoadParentAddData(id, sender, function () { $('#dialog-modal-add').modal('show'); });
            },
            ShowEditDialog: function () {
                $("#details").hide();
                LoadParentEditData(function () { $('#dialog-modal-edit').modal('show'); });
            },
            HideAddDialog: function () {
                $('#dialog-modal-add').modal('hide');
            },
            HideEditDialog: function () {
                $('#dialog-modal-edit').modal('hide');
            },
            ShowDeleteDialog: function () {
                $("#details").hide();
                $('#dialog-modal-delete').modal('show');
            },
            HideDeleteDialog: function () {
                $('#dialog-modal-delete').modal('hide');
            },
            ShowDetails: function () {                
                $("#index").hide();
                $("#details").show();                
            },
            ShowIndex: function () {
                $("#details").hide();
                $("#index").show();
            },
            SaveDialogCommit: function (formElement) {
                ViewModel.Add($(formElement).serialize(), function (result) {
                    ViewLogic.HideAddDialog();                    
                    for (p in result) {
                        $("#" + p, "#dialog-modal-add").parent().removeClass('error');
                        $("#" + p, "#dialog-modal-add").val('');
                        $("#" + p, "#dialog-modal-add").popover('disable');
                    }
                }, function (result) {
                    for (p in result.ValidationErrors) {
                        $("#" + p, "#dialog-modal-add").parent().addClass('error');
                        $("#" + p, "#dialog-modal-add").data('title', 'Validation Error');
                        $("#" + p, "#dialog-modal-add").data('content', result.ValidationErrors[p].join(','));
                        $("#" + p, "#dialog-modal-add").popover();
                    }
                });
            },
            UpdateDialogCommit: function (formElement) {
                ViewModel.Update($(formElement).serialize(), function (result) {
                    ViewLogic.HideEditDialog();
                    for (p in result) {
                        $("#" + p, "#dialog-modal-edit").parent().removeClass('error');
                        $("#" + p, "#dialog-modal-edit").val('');
                        $("#" + p, "#dialog-modal-edit").popover('disable');
                    }
                }, function (result) {                    
                    for (p in result.ValidationErrors) {
                        $("#" + p, "#dialog-modal-edit").parent().addClass('error');
                        $("#" + p, "#dialog-modal-edit").data('title', 'Validation Error');
                        $("#" + p, "#dialog-modal-edit").data('content', result.ValidationErrors[p].join(','));
                        $("#" + p, "#dialog-modal-edit").popover();
                    }
                });
            },
            DeleteDialogCommit: function () {
                ViewModel.Remove(ViewModel.Entity());
                ViewLogic.HideDeleteDialog();
            },
            ChangePage: function (entityName, cmd, id, sender) {
                window.location.href = "/" + entityName + "/SinglePage?cmd=" + cmd + "&id=" + id + "&sender=" + sender;
            }
        };

		var LoadParentEditData = function(callback){					 
						
						callback();
		};
		
		var LoadParentAddData = function(id, sender, callback){
			//for each parent, load data
				   
				
								callback();
		};
        var RelatedData = {
            Load: function (entityName, callback) {
                $.getJSON("/" + entityName + "/GetAll/", {}, function (data) {
                    callback(data);
                });
            }
        };  
        
    </script>
}
<div id="index">
    <div>
        <ul class="nav nav-tabs">
            <li class="active"><a href="#tabs-1">Industry</a></li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane active" id="tabs-1">
                <a data-toggle="modal" href="#dialog-modal-add" class="btn btn-primary btn-medium" data-bind="click: function(){ LoadParentAddData(null,'',function(){});}">
                        Add Industry</a>
            </div>
            <table class="table table-condensed">
                <thead>
                    <tr>
												<th>
                            Id
                        </th>						
												<th>
                            Description
                        </th>						
												<th>
                            Key
                        </th>						
																								<th>
							Categories
                        </th>
												<th>
							Technologies
                        </th>
												<th>
							ExpertProfiles
                        </th>
												<th>
							CompanyProfiles
                        </th>
												<th>
							Positions
                        </th>
																		<th>
                            Created
                        </th>						
												<th>
                            Updated
                        </th>						
						                        <th>
                        </th>
                    </tr>
                </thead>
                <tbody data-bind="foreach: Entities">
                    <tr>
												<td data-bind="text: Id">
                        </td>											
												<td data-bind="text: Description">
                        </td>											
												<td data-bind="text: Key">
                        </td>											
													
												<td data-bind="text: Categories().length + ' Categories'">
                        </td>
												<td data-bind="text: Technologies().length + ' Technologies'">
                        </td>
												<td data-bind="text: ExpertProfiles().length + ' ExpertProfiles'">
                        </td>
												<td data-bind="text: CompanyProfiles().length + ' CompanyProfiles'">
                        </td>
												<td data-bind="text: Positions().length + ' Positions'">
                        </td>
																		<td data-bind="text: Created">
                        </td>                        					
												<td data-bind="text: Updated">
                        </td>                        					
						                        <td>
                            <ul class="nav nav-pills" style="margin-bottom: 0px;">
                                <li class="dropdown" style="margin: 0px;"><a style="margin-top: 0px; margin-bottom: 0px;
                                        padding-bottom: 0px; padding-top: 0px;" class="dropdown-toggle" data-toggle="dropdown"
                                        href="#">Action<b class="caret"></b></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-toggle="modal" href="#dialog-modal-delete" data-bind="click: function(item){ $root.Select(item); }">
                                            Delete</a></li>
                                        <li><a data-toggle="modal" href="#dialog-modal-edit" data-bind="click: function(item){ $root.Select(item); LoadParentEditData(function(){}); }">
                                            Edit</a></li>
                                        <li><a href="#" data-bind="click: function(item){ $root.Select(item); ViewLogic.ShowDetails();}">
                                            Details</a></li>                           
                                    </ul>
                                </li>
                             </ul>
                        </td>                        
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div id="details" style="display: none;">
	<div>  
		<ul class="nav nav-tabs">
			<li class="active">
				<a href="#tab-IndustryDetails" data-toggle="tab">Industry Details</a>				
			</li>
						<li><a href="#childtabs-Category"  data-toggle="tab">Categories</a></li>								
						<li><a href="#childtabs-Technology"  data-toggle="tab">Technologies</a></li>								
						<li><a href="#childtabs-ExpertProfile"  data-toggle="tab">ExpertProfiles</a></li>								
						<li><a href="#childtabs-CompanyProfile"  data-toggle="tab">CompanyProfiles</a></li>								
						<li><a href="#childtabs-Project"  data-toggle="tab">Positions</a></li>								
					</ul>
		<div  class="tab-content">
			<div id="tab-IndustryDetails"  class="tab-pane active">
    			<div data-bind="with: Entity">
						
				<label>
                	Description
            	</label>
            	<input type="text" id="Description" name="Description"  data-bind="value: Description" readonly />        		
						
				<label>
                	Key
            	</label>
            	<input type="text" id="Key" name="Key"  data-bind="value: Key" readonly />        		
													<label>
                	Created
            	</label>
            	<input type="text" id="Created" name="Created"  data-bind="value: Created" readonly />        								
							<label>
                	Updated
            	</label>
            	<input type="text" id="Updated" name="Updated"  data-bind="value: Updated" readonly />        								
			        	<div>
            	<button data-bind="click: ViewLogic.ShowIndex" class="btn btn-primary">
                Back To List</button>        	
    		</div>
			</div>
		</div>
				
    	<div id="childtabs-Category" class="tab-pane"  data-bind="with: Entity">
        	<button class="btn btn-primary" data-bind="click: function(){ ViewLogic.ChangePage('Category', 'add', $data.Id,'Industry'); }">
        		Add Category</button>
			<button class="btn btn-primary" data-bind="click: function(){ ViewLogic.ChangePage('Category', 'index', $data.Id,'Industry'); }">
        		View Categories</button>
			<table class="table table-condensed">
        		<thead>
            		<tr>
					                	<th>
                		Id
                	</th>     
					                	<th>
                		Created
                	</th>     
					                	<th>
                		Updated
                	</th>     
					                	<th>
                		Description
                	</th>     
					                	<th>
                		Key
                	</th>     
					                	<th>
                		IndustryId
                	</th>     
					                	<th>
                		ParentCategoryId
                	</th>     
													
                	</tr>
            	</thead>
            	<tbody data-bind="foreach: Categories">
            		<tr>
					                		<td data-bind="text: Id">                                    
                    	</td>     
					                		<td data-bind="text: Created">                                    
                    	</td>     
					                		<td data-bind="text: Updated">                                    
                    	</td>     
					                		<td data-bind="text: Description">                                    
                    	</td>     
					                		<td data-bind="text: Key">                                    
                    	</td>     
					                		<td data-bind="text: IndustryId">                                    
                    	</td>     
					                		<td data-bind="text: ParentCategoryId">                                    
                    	</td>     
						
                	</tr>
            	</tbody>
        	</table>
    	</div>
				
    	<div id="childtabs-Technology" class="tab-pane"  data-bind="with: Entity">
        	<button class="btn btn-primary" data-bind="click: function(){ ViewLogic.ChangePage('Technology', 'add', $data.Id,'Industry'); }">
        		Add Technology</button>
			<button class="btn btn-primary" data-bind="click: function(){ ViewLogic.ChangePage('Technology', 'index', $data.Id,'Industry'); }">
        		View Technologies</button>
			<table class="table table-condensed">
        		<thead>
            		<tr>
					                	<th>
                		Id
                	</th>     
					                	<th>
                		Created
                	</th>     
					                	<th>
                		Updated
                	</th>     
					                	<th>
                		Name
                	</th>     
					                	<th>
                		IndustryId
                	</th>     
													
                	</tr>
            	</thead>
            	<tbody data-bind="foreach: Technologies">
            		<tr>
					                		<td data-bind="text: Id">                                    
                    	</td>     
					                		<td data-bind="text: Created">                                    
                    	</td>     
					                		<td data-bind="text: Updated">                                    
                    	</td>     
					                		<td data-bind="text: Name">                                    
                    	</td>     
					                		<td data-bind="text: IndustryId">                                    
                    	</td>     
						
                	</tr>
            	</tbody>
        	</table>
    	</div>
				
    	<div id="childtabs-ExpertProfile" class="tab-pane"  data-bind="with: Entity">
        	<button class="btn btn-primary" data-bind="click: function(){ ViewLogic.ChangePage('ExpertProfile', 'add', $data.Id,'Industry'); }">
        		Add ExpertProfile</button>
			<button class="btn btn-primary" data-bind="click: function(){ ViewLogic.ChangePage('ExpertProfile', 'index', $data.Id,'Industry'); }">
        		View ExpertProfiles</button>
			<table class="table table-condensed">
        		<thead>
            		<tr>
					                	<th>
                		Id
                	</th>     
					                	<th>
                		Created
                	</th>     
					                	<th>
                		Updated
                	</th>     
					                	<th>
                		Title
                	</th>     
					                	<th>
                		Description
                	</th>     
					                	<th>
                		Website
                	</th>     
					                	<th>
                		Skype
                	</th>     
					                	<th>
                		Facebook
                	</th>     
					                	<th>
                		Twitter
                	</th>     
					                	<th>
                		Linkedin
                	</th>     
					                	<th>
                		HourRate
                	</th>     
					                	<th>
                		DailyRate
                	</th>     
					                	<th>
                		MonthlyRate
                	</th>     
					                	<th>
                		AnnualRate
                	</th>     
					                	<th>
                		CommentRate
                	</th>     
					                	<th>
                		JobType
                	</th>     
					                	<th>
                		Experience
                	</th>     
					                	<th>
                		References
                	</th>     
					                	<th>
                		Availability
                	</th>     
					                	<th>
                		Other
                	</th>     
					                	<th>
                		AvailabilityStatus
                	</th>     
					                	<th>
                		ProfilePhoto
                	</th>     
					                	<th>
                		Cv
                	</th>     
					                	<th>
                		Location
                	</th>     
					                	<th>
                		IndustryId
                	</th>     
					                	<th>
                		CountryId
                	</th>     
													
                	</tr>
            	</thead>
            	<tbody data-bind="foreach: ExpertProfiles">
            		<tr>
					                		<td data-bind="text: Id">                                    
                    	</td>     
					                		<td data-bind="text: Created">                                    
                    	</td>     
					                		<td data-bind="text: Updated">                                    
                    	</td>     
					                		<td data-bind="text: Title">                                    
                    	</td>     
					                		<td data-bind="text: Description">                                    
                    	</td>     
					                		<td data-bind="text: Website">                                    
                    	</td>     
					                		<td data-bind="text: Skype">                                    
                    	</td>     
					                		<td data-bind="text: Facebook">                                    
                    	</td>     
					                		<td data-bind="text: Twitter">                                    
                    	</td>     
					                		<td data-bind="text: Linkedin">                                    
                    	</td>     
					                		<td data-bind="text: HourRate">                                    
                    	</td>     
					                		<td data-bind="text: DailyRate">                                    
                    	</td>     
					                		<td data-bind="text: MonthlyRate">                                    
                    	</td>     
					                		<td data-bind="text: AnnualRate">                                    
                    	</td>     
					                		<td data-bind="text: CommentRate">                                    
                    	</td>     
					                		<td data-bind="text: JobType">                                    
                    	</td>     
					                		<td data-bind="text: Experience">                                    
                    	</td>     
					                		<td data-bind="text: References">                                    
                    	</td>     
					                		<td data-bind="text: Availability">                                    
                    	</td>     
					                		<td data-bind="text: Other">                                    
                    	</td>     
					                		<td data-bind="text: AvailabilityStatus">                                    
                    	</td>     
					                		<td data-bind="text: Photo">                                    
                    	</td>     
					                		<td data-bind="text: Cv">                                    
                    	</td>     
					                		<td data-bind="text: Location">                                    
                    	</td>     
					                		<td data-bind="text: IndustryId">                                    
                    	</td>     
					                		<td data-bind="text: CountryId">                                    
                    	</td>     
						
                	</tr>
            	</tbody>
        	</table>
    	</div>
				
    	<div id="childtabs-CompanyProfile" class="tab-pane"  data-bind="with: Entity">
        	<button class="btn btn-primary" data-bind="click: function(){ ViewLogic.ChangePage('CompanyProfile', 'add', $data.Id,'Industry'); }">
        		Add CompanyProfile</button>
			<button class="btn btn-primary" data-bind="click: function(){ ViewLogic.ChangePage('CompanyProfile', 'index', $data.Id,'Industry'); }">
        		View CompanyProfiles</button>
			<table class="table table-condensed">
        		<thead>
            		<tr>
					                	<th>
                		Id
                	</th>     
					                	<th>
                		Created
                	</th>     
					                	<th>
                		Updated
                	</th>     
					                	<th>
                		Title
                	</th>     
					                	<th>
                		TagLine
                	</th>     
					                	<th>
                		Description
                	</th>     
					                	<th>
                		Website
                	</th>     
					                	<th>
                		Location
                	</th>     
					                	<th>
                		Photo
                	</th>     
					                	<th>
                		IndustryId
                	</th>     
					                	<th>
                		CountryId
                	</th>     
													
                	</tr>
            	</thead>
            	<tbody data-bind="foreach: CompanyProfiles">
            		<tr>
					                		<td data-bind="text: Id">                                    
                    	</td>     
					                		<td data-bind="text: Created">                                    
                    	</td>     
					                		<td data-bind="text: Updated">                                    
                    	</td>     
					                		<td data-bind="text: Title">                                    
                    	</td>     
					                		<td data-bind="text: TagLine">                                    
                    	</td>     
					                		<td data-bind="text: Description">                                    
                    	</td>     
					                		<td data-bind="text: Website">                                    
                    	</td>     
					                		<td data-bind="text: Location">                                    
                    	</td>     
					                		<td data-bind="text: Photo">                                    
                    	</td>     
					                		<td data-bind="text: IndustryId">                                    
                    	</td>     
					                		<td data-bind="text: CountryId">                                    
                    	</td>     
						
                	</tr>
            	</tbody>
        	</table>
    	</div>
				
    	<div id="childtabs-Project" class="tab-pane"  data-bind="with: Entity">
        	<button class="btn btn-primary" data-bind="click: function(){ ViewLogic.ChangePage('Position', 'add', $data.Id,'Industry'); }">
        		Add Position</button>
			<button class="btn btn-primary" data-bind="click: function(){ ViewLogic.ChangePage('Position', 'index', $data.Id,'Industry'); }">
        		View Positions</button>
			<table class="table table-condensed">
        		<thead>
            		<tr>
					                	<th>
                		Id
                	</th>     
					                	<th>
                		Created
                	</th>     
					                	<th>
                		Updated
                	</th>     
					                	<th>
                		Title
                	</th>     
					                	<th>
                		Description
                	</th>     
					                	<th>
                		StartDate
                	</th>     
					                	<th>
                		Duration
                	</th>     
					                	<th>
                		Location
                	</th>     
					                	<th>
                		JobType
                	</th>     
					                	<th>
                		CompanyProfileId
                	</th>     
					                	<th>
                		IndustryId
                	</th>     
					                	<th>
                		CountryId
                	</th>     
													
                	</tr>
            	</thead>
            	<tbody data-bind="foreach: positions">
            		<tr>
					                		<td data-bind="text: Id">                                    
                    	</td>     
					                		<td data-bind="text: Created">                                    
                    	</td>     
					                		<td data-bind="text: Updated">                                    
                    	</td>     
					                		<td data-bind="text: Title">                                    
                    	</td>     
					                		<td data-bind="text: Description">                                    
                    	</td>     
					                		<td data-bind="text: StartDate">                                    
                    	</td>     
					                		<td data-bind="text: Duration">                                    
                    	</td>     
					                		<td data-bind="text: Location">                                    
                    	</td>     
					                		<td data-bind="text: JobType">                                    
                    	</td>     
					                		<td data-bind="text: CompanyProfileId">                                    
                    	</td>     
					                		<td data-bind="text: IndustryId">                                    
                    	</td>     
					                		<td data-bind="text: CountryId">                                    
                    	</td>     
						
                	</tr>
            	</tbody>
        	</table>
    	</div>
				</div>
	</div>
</div>
<div id="dialog-modal-edit" class="modal hide fade" style="display: none;">
    <form data-bind="submit: ViewLogic.UpdateDialogCommit">
	<div class="modal-header">
        <a class="close" data-dismiss="modal">[x]</a>
        <h3>
            Edit Industry</h3>
    </div>	
    <div class="modal-body" data-bind="with: Entity">
						<input type="hidden" id="Id" name="Id" data-bind="value: Id" />
						<div class="control-group">
				<label>
					Created
				</label>
				<input type="text" readonly id="Created" name="Created" data-bind="value: Created" />
			</div>
					
			<div class="control-group">
				<label>
                	Description
            	</label>
            	<input type="text" id="Description" name="Description" placeholder="Enter Description here" data-bind="value: Description" />
        	</div>
					
			<div class="control-group">
				<label>
                	Key
            	</label>
            	<input type="text" id="Key" name="Key" placeholder="Enter Key here" data-bind="value: Key" />
        	</div>
			  
				
				</div>
        <div class="modal-footer">
        	<button class="btn" data-bind="click: ViewLogic.HideEditDialog">
            	Cancel</button>
        	<button type="submit" class="btn btn-primary">
            	Save</button>
    	</div>
    </form>
</div>
<div id="dialog-modal-delete" class="modal hide fade" style="display: none;">
	<div class="modal-header">
        <a class="close" data-dismiss="modal">[x]</a>
        <h3>
            Delete Factory</h3>
    </div>
    <div class="modal-body" data-bind="with: Entity">
        <h3>
            Do you reallt want to delete this Industry?</h3>
    </div>
    <div class="modal-footer">
        <button class="btn" data-bind="click: ViewLogic.HideDeleteDialog">
            Cancel</button>
        <button type="submit" class="btn btn-primary" data-bind="click: ViewLogic.DeleteDialogCommit">
            Confirm Delete</button>
    </div>
</div>
<div id="dialog-modal-add" class="modal hide fade" style="display: none;">
    <form data-bind="submit: ViewLogic.SaveDialogCommit">
	<div class="modal-header">
        <a class="close" data-dismiss="modal">[x]</a>
        <h3>
            Add Industry</h3>
    </div>
    <div class="modal-body">       
					<div class="control-group">
            	<label>
                Description
            	</label>
            	<input type="text" id="Description" name="Description" placeholder="Enter Description here" />
        	</div>			
						<div class="control-group">
            	<label>
                Key
            	</label>
            	<input type="text" id="Key" name="Key" placeholder="Enter Key here" />
        	</div>			
							        
    </div>
	<div class="modal-footer">
        <button class="btn" data-bind="click: ViewLogic.HideAddDialog">
            Cancel</button>
        <button type="submit" class="btn btn-primary">
            Save</button>        
    </div>
    </form>
</div>
<div id="debug" data-bind="visible: Debug">
    <hr />
    <h2>
        Debug (To turn of debugging set <i>"var debugEnabled = false;"</i> in _Layout.cshtml)</h2>
    <div data-bind="text: ko.toJSON(ViewModel)">
    </div>
</div>
